package com.ourygo.fileselect.util;
import android.content.*;
import com.ourygo.fileselect.*;
import com.ourygo.fileselect.bean.*;
import java.util.*;
import android.text.*;

public class SharedPreferencesUtil
{
	
	public static SharedPreferences getShareBookMark(Context context){
		return context.getSharedPreferences("BookMark",context.MODE_PRIVATE);
	}
	
	public static List<BookMark> getBookMarkList(Context context){
		List<BookMark> lb= new ArrayList<>();
		Map<String, ?> map = getShareBookMark(context).getAll();
		Iterator iter = map.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			BookMark bm=new BookMark();
			String key = (String) entry.getKey();
			String val = (String) entry.getValue();
			bm.setName(val);
			bm.setPath(key);
			bm.setIcon(R.drawable.listfile_folder);
			lb.add(bm);
		}
		
		return lb;
	}
	
	
	public static boolean addBookMark(Context context,BookMark bm){
		SharedPreferences sh=getShareBookMark(context);
		if(TextUtils.isEmpty(sh.getString(bm.getPath(),null))){
			return sh.edit().putString(bm.getPath(),bm.getName()).commit();
		}
		return false;
	}
	
	public static boolean removeBookMark(Context context,BookMark bm){
		return getShareBookMark(context).edit().remove(bm.getPath()).commit();
	}
	
	
}
